package com.elder.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.elder.business.domain.ElderlyApartmentAnnouncementsVO;
import com.elder.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.elder.common.annotation.Log;
import com.elder.common.core.controller.BaseController;
import com.elder.common.core.domain.AjaxResult;
import com.elder.common.enums.BusinessType;
import com.elder.business.domain.ElderlyApartmentAnnouncements;
import com.elder.business.service.IElderlyApartmentAnnouncementsService;
import com.elder.common.utils.poi.ExcelUtil;
import com.elder.common.core.page.TableDataInfo;

/**
 * 公告信息Controller
 * 
 * @author elder
 * @date 2023-11-26
 */
@RestController
@RequestMapping("/business/announcements")
public class ElderlyApartmentAnnouncementsController extends BaseController
{
    @Autowired
    private IElderlyApartmentAnnouncementsService elderlyApartmentAnnouncementsService;

    /**
     * 查询公告信息列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(String title,String postedName, String postDate ,String expiryDate,Integer pageNum,Integer pageSize)
    {
        return elderlyApartmentAnnouncementsService.selectElderlyApartmentAnnouncementsList(title,postedName,postDate,expiryDate,pageNum,pageSize);
    }
    /**
     * 获取公告信息详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(elderlyApartmentAnnouncementsService.selectElderlyApartmentAnnouncementsById(id));
    }

    /**
     * 新增公告信息
     */
    @Anonymous
    @Log(title = "公告信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElderlyApartmentAnnouncements elderlyApartmentAnnouncements)
    {
        return toAjax(elderlyApartmentAnnouncementsService.insertElderlyApartmentAnnouncements(elderlyApartmentAnnouncements));
    }

    /**
     * 修改公告信息
     */
    @Anonymous
    @Log(title = "公告信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElderlyApartmentAnnouncementsVO elderlyApartmentAnnouncements)
    {
        return toAjax(elderlyApartmentAnnouncementsService.updateElderlyApartmentAnnouncements(elderlyApartmentAnnouncements));
    }

    /**
     * 删除公告信息
     */
    @Anonymous
    @Log(title = "公告信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(elderlyApartmentAnnouncementsService.deleteElderlyApartmentAnnouncementsByIds(ids));
    }

    /***
     * @description 获取最近发布的公告信息
     * @return TableDataInfo
     * @author zyk
     * @date 2024/2/28 22:16
     */
    @Anonymous
    @RequestMapping("/getRecentContent")
    public TableDataInfo getContent()
    {
        return elderlyApartmentAnnouncementsService.getRecentAnnouncementsContent();
    }
}
